import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Question21 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        
        int n = in.nextInt();
        int[] a = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            sum += a[i];
        }

        Arrays.sort(a);

        if (a[0] == a[n - 1]) {
            System.out.println(1);
            return ;
        }

        int ret = Integer.MAX_VALUE;

        for (int i = 0; i < n; i++) {
            int temp = a[i];
            int tempCnt = 0;

            int otherSum = sum - temp;
            int avg = Math.round(otherSum / (n - 1));

            if (avg == temp) {
                ret++;
            }

            for (int j = 0; j < n; j++) {
                if (j == i) {
                    continue;
                }

                tempCnt += Math.abs(a[j] - avg);
            }

            ret = Math.min(ret, tempCnt);
        }

        System.out.println(ret);
    }
}